package com.wx.rabbitmq;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @ClassName MqConnection
 * @Author wx
 * @Description 连接工厂
 * @Date 2018-11-22-22:41
 */
public class MqConnection {

    private static  ConnectionFactory connectionFactory = null;

    static {
        // 创建一个ConnectionFactory
        connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("localhost");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/");
    }


    /**
     * @methodName: getConnection
     * @author: wx
     * @description: 获取连接工厂生产的连接
     * @param 
     * @date: 2018/11/22
     * @return: com.rabbitmq.client.Connection
     */
    public static  Connection  getConnection() throws IOException, TimeoutException {
        // 通过连接工厂创建连接
        Connection connection = connectionFactory.newConnection();
        return connection;
    }

}
